package worker;

import java.io.Serializable;

import org.objectweb.proactive.api.PAActiveObject;

public class Maillon implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2444973711236603051L;

	protected ManagerImpl manager;
	protected boolean free;
	protected String url;

	
	public Maillon () { }
	
	public Maillon (ManagerImpl m){
		this.manager = m;
		this.free = true;
		this.url = PAActiveObject.getActiveObjectNodeUrl(m);
	}

	public Maillon (ManagerImpl m, boolean f){
		this.manager = m;
		this.free = f;
		this.url = PAActiveObject.getActiveObjectNodeUrl(m);
	}
	
	
	public String getUrl () { return url; }
	

	/**
     * Retourne un manager.
     * @return Une instance de manager.
     */
	public ManagerImpl getManager() {
		return manager;
	}

	/**
     * Met a jour un manager.
     * @param manager.
     */
	public void setManager(ManagerImpl manager) {
		this.manager = manager;
	}
	
	/**
     * Decrit l'etat d'un manager.
     * @return un etat.
     */
	public boolean isFree() {
		return free;
	}

	/**
     * Met a jour l'etat d'un manager.
     * @param free.
     */
	public void setFree(boolean free) {
		this.free = free;
	}

	/**
     * Test des managers deux a deux. (pour utiliser indexOf() dans List)
     * @return un booleen entre la comparaison de deux managers.
     */
	@Override
	public boolean equals (Object m) {
		return (m instanceof Maillon) && manager.equals(((Maillon) m).getManager());
	}
	
	/**
	 * Retourne le hashcode associe a un manager (va avec equals() )
	 */
	public int hashCode () {
		return manager.hashCode();
	}
}
